/**
@author
name:"崔赛豪"  
time:"2024-11-22  10:07:00"
*/

/**
@description: 分包商认定
*/
$NG.AllReady(function (
	page,
	{
		useValuesChange,
		useClick,
		useUpdateRow,
		useUpdateRows,
		useDataIndexChange,
		useBeforeClick,
	}
) {
	let message = ""
	//获取服务于工程的表格
	var mstform = $NG.getCmpApi("p_form_subcontractor_m");
	var tab1 = $NG.getCmpApi("p_form_subcontractor_d1"); //财务明细
	var tab2 = $NG.getCmpApi("p_form_subcontractor_d2"); //服务于工程明细
	var tab3 = $NG.getCmpApi("p_form_subcontractor_d3"); //资质证书明细
	var tab4 = $NG.getCmpApi("p_form_subcontractor_d4"); //案例情况明细

    $NG.getCmpApi("toolbar_p_form_subcontractor_d1").getItem("imp").setHidden();
    $NG.getCmpApi("toolbar_p_form_subcontractor_d4").getItem("imp").setHidden();
    $NG.getCmpApi("toolbar_p_form_subcontractor_d1").getItem("attachment").setHidden();
    $NG.getCmpApi("toolbar_p_form_subcontractor_d2").getItem("attachment").setHidden();
    $NG.getCmpApi("toolbar_p_form_subcontractor_d3").getItem("attachment").setHidden();
    $NG.getCmpApi("toolbar_p_form_subcontractor_d4").getItem("attachment").setHidden();
	if ($NG.getCmpApi("p_form_subcontractor_m")) {
		cntMFilter();
		$NG.execServer("ObtainQualificationInfo", {}, function (res) {
			//获取都有那些资质证书 排列到明细表上
			// console.log(JSON.parse(res.data), "ObtainQualificationInfo");
			const originalArray = JSON.parse(res.data);
			const newArray = originalArray.map((obj) => {
				return {
					checked: false,
					u_zzname: obj.extendObjects.c_name,
				};
			});
			if (page.oType == "add") {
                const nDate = new Date();
                console.log(nDate);
                
                mstform.getItem("u_sq_date").setValue(nDate)
				// console.log(newArray, "newArray");
				//tab3.addRows(newArray);
			}
		});

		getPtInfoByPhid();
	}

    // console.log(  $NG.getPageUI());
    
    useValuesChange(({args})=>{
        if(args[0].u_is_ssgs?.key == 1){  
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_subcontractor_m.u_gsdm.setProps({
                    disabled: true, //只读
                });
                mstform.getItem("u_gsdm").setValue('');
            });
        }else{
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_subcontractor_m.u_gsdm.setProps({
                    disabled: false, //只读
                });
            });
        }
    },"p_form_subcontractor_m.u_is_ssgs")
    useValuesChange(({args})=>{
        if(args[0].u_is_tlfbal?.key == 2){         
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_subcontractor_m.u_alpg.setProps({
                    disabled: true, //只读
                });
                mstform.getItem("u_alpg").setValue('');
            });
        }else{
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_subcontractor_m.u_alpg.setProps({
                    disabled: false, //只读
                });
            });
        }
    },"p_form_subcontractor_m.u_is_tlfbal")
    useValuesChange(({args})=>{
        if(args[0].u_is_fbjscn?.key == 2){
            
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_subcontractor_m.u_reason.setProps({
					required: true, //必输
					
                });
            });
        }else{
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_subcontractor_m.u_reason.setProps({
					required: false, //必输
                });
            });
        }
    },"p_form_subcontractor_m.u_is_fbjscn")
    useValuesChange(({args})=>{;
        $NG.updateUI((updater, state) => {
            console.log('过滤参数检查', updater);
            updater.fieldSetForm.p_form_subcontractor_m.u_province.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_subcontractor_m').getItem('u_nation').getValue();
                    if (!phid_pc) {
                        $NG.alert("请先选择国家");
                        return false;
                    } else {
                        return true;
                    }
                },
                ...{
                    clientSqlFilter: {
                        nationid:args[0].u_nation.origin.nationno
                    }
                },
            });
        });
    },"p_form_subcontractor_m.u_nation")

    useValuesChange(({args})=>{
        console.log(args[0],'省份');
        $NG.updateUI((updater, state) => {
            console.log('过滤参数检查', updater);
            updater.fieldSetForm.p_form_subcontractor_m.u_city.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_subcontractor_m').getItem('u_province').getValue();
                    if (!phid_pc) {
                        $NG.alert("请先选择省份");
                        return false;
                    } else {
                        return true;
                    }
                },
                ...(!!$NG.getCmpApi('p_form_subcontractor_m').getItem('u_province').getValue() && {
                    clientSqlFilter: {
                        provinceno:mstform.getItem("u_province").getValue()
                    }
                }),
            });
        });
    },"p_form_subcontractor_m.u_province")

useValuesChange(({args})=>{
    console.log('城市',args[0]);
    $NG.updateUI((updater, state) => {
        console.log('过滤参数检查', updater);
        updater.fieldSetForm.p_form_subcontractor_m.u_region.setProps({
            onBeforeOpen: async () => {
                var phid_pc = $NG.getCmpApi('p_form_subcontractor_m').getItem('u_province').getValue();
                if (!phid_pc) {
                    $NG.alert("请先选择省份");
                    return false;
                } else {
                    return true;
                }
            },
            ...(!!$NG.getCmpApi('p_form_subcontractor_m').getItem('u_province').getValue() && {
                clientSqlFilter: {
                    cityno:mstform.getItem("u_city").getValue()
                }
            }),
        });
    });
},"p_form_subcontractor_m.u_city")
useDataIndexChange(({ args, instance }) => {
    // 获取当前行数据
    console.log(args[0]);
    getBankNo(args)
    instance.updateRow(args[0]);
}, 'p_form_subcontractor_d1.u_kh_bank');
	/**
	 *@function:过滤项目
	 */
    async function getBankNo(args) {
        await $NG.execServer('getBankNo',{ bankname:`'${args[0].u_kh_bank_EXName}'`},function (res) {
            const data = JSON.parse(res.data);
            console.log(data);
            args[0].u_lhh = data[0].extendObjects.bankno;
            const rows = tab1.getRows();
            const dataIsDbclick = [];
            rows.forEach((items) => {
              if (dataIsDbclick.indexOf(String(items.u_cnt_item)) == -1) {
                dataIsDbclick.push(String(items.u_cnt_item));
                // console.log("不包括", items.u_cnt_item, dataIsDbclick);
              } else {
                // console.log("包括", items.u_cnt_amt);
                // 已有当前清单
                items.u_cnt_amt = null;
              }
            });
        
            tab1.refreshView();
        })
    }
	function cntMFilter() {
		if (!mstform.getItem("phid_pc")?.getValue()) {
			return;
		}
		$NG.updateUI((updater, state) => {
			updater.fieldSetForm.p_form_subcontractor_m.u_fbs_name.setProps({
				onBeforeOpen: async () => {},
				...{
					clientSqlFilter: `suppclass_main = 8570000000000008 or parentid = 8570000000000008`, //过滤项目
				},
			});
		});
	}
	/**
	 *@license: 	 //表头字段变化逻辑END	//表头字段变化逻辑BEGIN监听   pc
	 */
	useValuesChange(({ args }) => {
		getPtInfoByPhid();
		// cntMFilter();
	}, "p_form_subcontractor_m.phid_pc");

	/**
	 *@license: 	 监听分包商信息变化
	 */
	useValuesChange(({ args }) => {
		console.log(args[0], "监听分包商信息变化");
		console.log(args[0].u_fbs_name.name, "212312");
		$NG.execServer(
			"fbsrdxx",
			{
				 compname: `'${args[0].u_fbs_name.name}'`
			},
			function (res) {
                console.log(res);
                
				const datas = JSON.parse(res.data)[0].extendObjects;
				console.log(datas, "ddatasatascompno");
				console.log(datas.user_frsfz, "datascompno");
				$NG.updateState((updater) => {
					updater.data.p_form_subcontractor_m.setProps({
						u_fr_card: datas.cardno, //身份证
						u_social_credit_code: datas.unisocialcredit, //社会信用代码
						u_cl_date: datas.ng_insert_dt, //成立日期
						u_legal_person: datas.taxpayername, //法人
						u_gsgm: datas.person_flg, //公司规模
						u_registered_capital: datas.regmoney, //注册资本
						u_contacts: datas.person, //联系人
						u_contacts_phone: datas.phone, //联系电话
						u_name1: datas.compname,
						u_sjzj: datas.user_sj_zj,
						u_yyfw: datas.user_jyfw,
						u_cbrs: datas.user_cbrs,
						u_yyzddt: datas.user_yyzzdq_dt,
						u_address: datas.user_zc_address,
						// u_region: datas.user_zc_address,

						// u_address: datas.user_zc_address, //注册地址
						// u_supply_att: {
						// 	value: datas.user_gyssx,
						// 	label: datas.user_gyssx,
						// },
						// u_brand: datas.simpname,
					});
				});
				if (datas.region_id) {
					console.log(datas.region_id, "datas.region_id");
					$NG.execServer("getAddressToId", { phid: datas.region_id }, function (res2) {
					  const data2 = JSON.parse(res2.data)[0].extendObjects; //单返回值
					  console.log(data2, "data2");
					  $NG.updateState((updater) => {
						updater.data.p_form_subcontractor_m.setProps({
						  u_nation: {
							value: data2.nationno,
							label: data2.nationname,
						  },
						  u_province: {
							value: data2.provinceno,
							label: data2.provincename,
						  },
						  u_city: {
							value: data2.cityno,
							label: data2.cityname,
						  },
						  u_region: {
							value: data2.regionno,
							label: data2.regionname,
						  },
						  u_xxdz: datas.detail_add,
						});
					  });
					});
				  }
				  if (datas.cardno) {
					$NG.alert(`该法人${datas.taxpayername}已认证过${args[0].u_fbs_name.name}`)
				  }
				  console.log(mstform.getItem("u_fbs_name").getValue());
				  
				  $NG.execServer(
					"searchGysTt",
					{ phid: mstform.getItem("u_fbs_name").getValue() },
					function (res) {
						const datas = JSON.parse(res.data)[0].extendObjects;
						console.log(datas, "datas");
						//帮助字段赋值
						if (datas.user_status == 1||datas.user_status == 2||datas.user_status == 3) {
							$NG.updateState((updater) => {
								updater.data.p_form_subcontractor_m.setProps({
									u_is_tcjy: 1,
								});
							});
						}else{
							$NG.updateState((updater) => {
								updater.data.p_form_subcontractor_m.setProps({
									u_is_tcjy: 2,
								});
							});
						}
					}
				);
				// $NG.execServer(
				// 	"yrdgysxx",
				// 	{
				// 		cardid: datas.user_frsfz,
				// 	},
				// 	function (res) {
				// 		let data = JSON.parse(res.data);
				// 		console.log(data, "resresres");
				// 		const removeCompno = (array, compno) => {
				// 			return array.filter(
				// 				(item) => item.extendObjects.compno !== compno
				// 			);
				// 		};

				// 		const filteredData = removeCompno(data, "CS202421");
				// 		const compnames = filteredData.map(
				// 			(item) => item.extendObjects.compname
				// 		);

				// 		console.log(compnames, "compnames");
				// 		if (data.length > 1) {
				// 			$NG.alert("您认证过其他公司");
				// 			$NG.alert(compnames);
				// 		}
				// 	}
				// );
			}
		);
	}, "p_form_subcontractor_m.u_fbs_name");
	console.log(JSON.parse(localStorage.getItem("fbsrdjy")), "huoquzhi");

	useUpdateRows(({ args, table }) => {
		const rows4 = tab4.getRows();
		reduceTable2(rows4);
		mstform.getItem("u_alpg").setValue(rows4.length);
	}, "p_form_subcontractor_d4");
	/**
	 *@license:监听服务于工程表 1.累计分包金额
	 */
	//8.表体编辑更新（单元格）
	useDataIndexChange(({ args }) => {
		const row = args[0];
		console.log(args[1].update.originValue.phid_resbs, "sssssssss 1.sssss");
		if (args[1].update.originValue.phid_resbs) {
			$NG.execServer(
				"getAutoType",
				{ phid: args[1].update.originValue.phid_resbs },
				function (res) {
					const datas = JSON.parse(res.data)[0].extendObjects;
					console.log(datas, "获取值datas");
					row.u_fbzl = datas.f_phid;
					row.u_fbzl_EXName = datas.fname;
					row.u_fbdl = datas.g_phid;
					row.u_fbdl_EXName = datas.gname;
					row.u_fbxl = datas.phid_resbs;
					row.u_fbxl_EXName = datas.name;
					tab2.updateRow(row);
					tab2.refreshView();
				}
			);
		}
	}, "u_itemname");
	useDataIndexChange(({ args, instance }) => {
		const row = args[0];
		console.log(args[0].u_fbxl);
		if (args[0].u_fbxl) {
			$NG.execServer(
				"getWlzdl",
				{ xl_phid: `${args[0].u_fbxl}` },
				function (res) {
					console.log(res);
					
					const datas = JSON.parse(res.data)[0].extendObjects;
					console.log(datas, "获取值datas");
					row.u_fbzl = datas.zl_phid;
					row.u_fbzl_EXName = datas.zl_name;
					row.u_fbdl = datas.dl_phid;
					row.u_fbdl_EXName = datas.dl_name;
					tab2.updateRow(row);
					tab2.refreshView();
				}
			);
		}
	}, 'p_form_subcontractor_d2.u_fbxl');


	useUpdateRows(({ args }) => {
		console.log(args, "getRuleInfoTableData");
		const rows = args[0];
		rows.forEach((row) => {
			// $NG.execServer("autoSelectType", { id: row.u_itemname }, function (res) {
			// 	let resWzxlData = JSON.parse(res.data)[0].extendObjects;
			// 	console.log(res.status, "返回值resWzxlData");
			// 	console.log(resWzxlData, "resWzxlData返回值resWzxlData??");
			// 	if (res.status == "success") {
			// 	} else {
			// 		$NG.alert("未查询到该物资类型");
			// 	}
			// });
		});
		reduceTable1(rows);
	}, "p_form_subcontractor_d2");
	/**
	 *@function:计算分包总额
	 */
	function reduceTable1(rows) {
		let totalAmount = 0;
		rows.forEach((row) => {
			console.log(row.u_fb_amt, "row.u_fb_amt");

			if (isNaN(row.u_fb_amt)) return; //如果u_fb_amt不是数字，则跳过该行
			totalAmount += row.u_fb_amt;
		});

		$NG.updateState((updater) => {
			updater.data.p_form_subcontractor_m.setProps({
				u_fbze: totalAmount,
			});
		});
	}

	// 按钮点击前事件
	useBeforeClick(async function ({ args }) {
		let flag;
		const rows3 = tab3.getRows();
		const rows4 = tab4.getRows();
		const tab2Rows = tab2.getRows();
		await $NG.execServer("fbsrdjy", {}).then((res) => {
			const JYGZ = JSON.parse(res.data);
			tab2Rows.forEach((row, index) => {
				//保存的时候用于校验服务于工程与工程的表格 联合 案例表格 以及表头校验是否满足条件
				//判断有没有小类和注册资金 如果有进行下一步没有就进行没有的逻辑
				if (row.u_fbzl && row.u_fb_amt) {
					const JYGZS = JYGZ.flatMap((item) => item.extendObjects || []); //处理校验规则数据
					//过滤后的校验规则
					const FilterJYGZS = JYGZS.filter((obj) => {
						//判断是否有符合的过滤条件
						if (obj.u_fbzl != row.u_fbzl) return false;
						return true;
					});
					if (FilterJYGZS.length == 0) {
						flag = false;
						$NG.alert(
							"服务于工程明细表第" +
								(index + 1) +
								"行 查找不到无该务类别校验要求"
						);
					}
					// else if (FilterJYGZS.length == 1) {
					// 	console.log(FilterJYGZS[0], "JYGZS[0]");
					// }
					else if (FilterJYGZS.length >= 1) {
						const filtersObj = FilterJYGZS.find((obj) => {
							//可能会有范围 都满足 操作问题
							return FbeFlag(obj.u_db_amt, row.u_fb_amt);
						});
						console.log(filtersObj, "根据分包额筛选出来的filtersObj");
						if (filtersObj) {
							//1.注册时间校验
							if (
								zcsjFlag(
									mstform.getItem("u_cl_date").getValue(),
									filtersObj.u_zcsj,
									index
								)
							) {
							} else {
								console.log(
									mstform.getItem("u_cl_date").getValue(),
									"mstform.getItem('u_cl_date').getValue()"
								);
								console.log("bugdddd");
								flag = false;
							}
							//2.注册资金校验
							console.log(filtersObj.u_zczj, "filtersObj.u_zczj");
							if (
								zczjFlag(
									filtersObj.u_zczj,
									mstform.getItem("u_registered_capital").getValue(),
									index
								)
							) {
								if (filtersObj.u_is_dyfbed) {
									if (
										mstform.getItem("u_registered_capital").getValue() >=
										row.u_fb_amt
									) {
										//大于不用管
									} else {
										//小于分包额度
										flag = false;
										$NG.alert(
											"服务于工程明细表第" +
												(index + 1) +
												"行,注册资金小于分包额度不满足条件"
										);
									}
								}
							} else {
								$NG.alert(
									`服务于工程明细表第${index + 1}行,注册资金不满足条件${
										filtersObj.u_zczj
									}万元`
								);
								flag = false;
							}
							// /	// 3.公司规模  --> 根据查找出规则校验 u_gsgm
							if (
								rygmfbeFlag(
									filtersObj.u_rygmfbe,
									mstform.getItem("u_gsgm").getValue(),
									index
								)
							) {
							} else {
								flag = false;
								$NG.alert(
									`服务于工程明细表第${index + 1}行,公司规模不满足条件${
										filtersObj.u_rygmfbe
									}人`
								);
							}

							if (filtersObj.u_min) {
								const u_fb_amt = getWan(row.u_fb_amt);
								// Math.floor((分包额 - 最大值) / 百万单位) * 人数基数 + 基准人数;
								if (u_fb_amt > filtersObj.u_maxz) {
									let resData =
										Math.floor(
											(u_fb_amt - filtersObj.u_maxz) / filtersObj.u_zjjs
										) *
											filtersObj.u_bwrs +
										filtersObj.u_jzrs;
									console.log(row.u_zyjsry, "row.u_zyjsry");
									console.log(resData, "resData");
									if (row.u_zyjsry >= resData) {
									} else {
										flag = false;
										$NG.alert(
											`服务于工程明细表第${
												index + 1
											}行,专业技术人员人数不满足条件${resData}人`
										);
									}
								} else {
									if (row.u_zyjsry >= filtersObj.u_jzrs) {
									} else {
										flag = false;
										$NG.alert(
											`服务于工程明细表第${
												index + 1
											}行,专业技术人员人数不满足条件${filtersObj.u_jzrs}人`
										);
									}
								}
							} else if (
								filtersObj.u_jzrs &&
								!filtersObj.u_min &&
								!filtersObj.u_maxz
							) {
								console.log("filtersObj.u_jzrs", filtersObj.u_jzrs);

								if (row.u_zyjsry >= filtersObj.u_jzrs) {
								} else {
									flag = false;
									$NG.alert(
										`服务于工程明细表第${
											index + 1
										}行,专业技术人员人数不满足条件${filtersObj.u_jzrs}人`
									);
								}
							} else {
								if (filtersObj.u_zjjs && filtersObj.u_bwrs) {
									let resData1 =
										Math.floor(u_fb_amt / filtersObj.u_zjjs) *
										filtersObj.u_bwrs;
									if (row.u_zyjsry >= resData1) {
									} else {
										flag = false;
										$NG.alert(
											`服务于工程明细表第${
												index + 1
											}行,专业技术人员人数不满足条件${resData1}人`
										);
									}
								}
							}
							if (Number(filtersObj.u_aqy) <= row.u_zzaqy) {
							} else {
								flag = false;
								$NG.alert(
									`服务于工程明细表第${index + 1}行,安全生产人员不满足条件${
										filtersObj.u_aqy
									}人`
								);
							}
							if (Number(filtersObj.u_zlry) <= row.u_zzzlry) {
							} else {
								flag = false;
								$NG.alert(
									`服务于工程明细表第${index + 1}行,专业质量人员不满足条件${
										filtersObj.u_zlry
									}人`
								);
							}

							if (Number(filtersObj.u_alsl) <= rows4.length) {
							} else {
								flag = false;
								$NG.alert(
									`服务于工程明细表第${index + 1}行,案例数量不满足${
										filtersObj.u_alsl
									}个`
								);
							}

							///判断ios9001条件是否需要具备
							if (filtersObj.u_iso) {
								if (mstform.getItem("u_iso_zs").getValue()) {
								} else {
									flag = false;

									$NG.alert(
										`服务于工程明细表第${index + 1}行,缺乏ios9001证书条件`
									);
								}
							}
						}
					}
				} else {
					$NG.alert(
						"服务于工程明细表第" + (index + 1) + "行分包额或服务类别为空"
					);
					flag = false;
				}
			});
		});

		rows3.forEach((row, index) => {
			if (row.u_dq_dt) {
				console.log(row.u_dq_dt, "row.u_dq_dt");
			}
		});
		rows4.forEach((row, index) => {
			if (row.u_cnt_dt) {
				console.log(
					isWithinTwoYears(row.u_cnt_dt),
					"isWithinTwoYears(row.u_cnt_dt)"
				);
				if (isWithinTwoYears(row.u_cnt_dt)) {
				} else {
					flag = false;
					$NG.alert(`案例情况第${index + 1}行,注册时间不满足条件近${"两"}年`);
				}
			}
		});
		if (findMaxAmountRows4(rows4) && findMaxAmountTab2Rows(tab2Rows)) {
			console.log(findMaxAmountRows4(rows4), "findMaxAmountRows4(tab2Rows)");
			console.log(
				findMaxAmountTab2Rows(tab2Rows),
				"findMaxAmountTab2Rows(tab2Rows)"
			);
			if (findMaxAmountTab2Rows(tab2Rows) <= findMaxAmountRows4(rows4)) {
			} else {
				flag = false;
				$NG.alert(
					`在你提交的案例合同中,其中最大金额的一个合同金额,小于你这次在工程服务中填写的最大分包额`
				);
			}
		}

		console.log(flag, "save按钮点击");
		return flag;
	}, "save");

	useClick((prop) => {
		console.log(prop, "ccc");
		return false;
	}, "save");
	/**
	 *@function:带出项目信息
	 */
    console.log(mstform);
    
	function getPtInfoByPhid() {
		if (mstform.getItem("phid_pc").getValue()) {
			$NG.execServer(
				"getPtInfoByPhid",
				{ phid: mstform.getItem("phid_pc").getValue() },
				function (res) {
					const datas = JSON.parse(res.data)[0].extendObjects;
					console.log(datas, "datas");
					//帮助字段赋值
					$NG.updateState((updater) => {
						updater.data.p_form_subcontractor_m.setProps({
							// u_supply_att: datas.u_supply_att, //计划完工日期
							// u_supply_name: datas.u_supply_name, //计划竣工日期
							bill_no: datas.pc_no, //项目编码
							u_division: {
								//事业部or组织
								value: datas.org_phid,
								label: datas.org_name,
							},
							u_regional_center: {
								//区域中心
								value: datas.regional_center_phid,
								label: datas.regional_center_name,
							},
							u_product_line: {
								//产品线
								value: datas.midwife_phid,
								label: datas.midwife_name,
							},
						});
					});
				}
			);
		}
	}
	/**
	 *@function:计算案情数量 平均值 和 总额度
	 */
	function reduceTable2(rows) {
		console.log("进入reduceTable2", rows);
		const validAmounts = rows
			.filter((item) => item.u_cnt_amt != null && !isNaN(item.u_cnt_amt))
			.map((item) => item.u_cnt_amt);

		// 计算总额度
		const totalAmount =
			validAmounts.length > 0
				? validAmounts.reduce((sum, amt) => sum + amt, 0)
				: null;

		console.log(`总额度: ${totalAmount}`);

		// 计算平均值
		const avgAmount =
			validAmounts.length > 0
				? validAmounts.reduce((sum, amt) => sum + amt, 0) / validAmounts.length
				: null;

		console.log(`平均值: ${avgAmount}`);
		$NG.updateState((updater) => {
			updater.data.p_form_subcontractor_m.setProps({
				u_alpg: rows.length,
				u_snqd_amt: totalAmount, //近三年同类工程总签单额（万元）
				u_snpj_amt: avgAmount, //近三年同类工程年均签单额（万元）
			});
		});
	}
});


//// 找出rows4合同数组中金额最大的对象
function findMaxAmountRows4(rows4) {
	if (rows4.length === 0) {
		return null;
	}
	return rows4.reduce((maxAmount, current) => {
		return current.u_cnt_amt > maxAmount ? current.u_cnt_amt : maxAmount;
	}, 0);
}
//// 找出rows2明细分包额数组中金额最大的对象
function findMaxAmountTab2Rows(tab2Rows) {
	if (tab2Rows.length === 0) {
		return null;
	}
	return tab2Rows.reduce((maxAmount, current) => {
		return current.u_fb_amt > maxAmount ? current.u_fb_amt : maxAmount;
	}, 0);
}

//判断是不是在两年之内
function isWithinTwoYears(dateStr) {
	const givenDate = new Date(dateStr);
	const currentDate = new Date();
	const twoYearsAgo = new Date(currentDate);
	twoYearsAgo.setFullYear(currentDate.getFullYear() - 2);
	return givenDate >= twoYearsAgo && givenDate <= currentDate;
}
//第一个是条件 第二个是人员规模u_rygmfbe, u_gsgm
function rygmfbeFlag(u_rygmfbe, u_gsgm, index) {
	console.log(u_rygmfbe, "u_rygmfbe");
	console.log(u_gsgm, "u_gsgm");
	console.log(index, "index");
	const match = u_rygmfbe
		?.replace(/＞/g, ">")
		.replace(/＜/g, "<")
		.replace(/≥/g, ">=")
		.replace(/≤/g, "<=")
		.match(/(<=|>=|<|>)(\d+)/);
	if (match) {
		const [_, symbol, number] = match;
		const num = parseFloat(number);
		const amt = u_gsgm;
		console.log(amt, "rygmfbeFlag", num, "rygmfbeFlag");
		// 符号匹配逻辑
		switch (symbol) {
			case "<":
				return amt < num;
			case ">":
				return amt > num;
			case "<=":
				return amt <= num;
			case ">=":
				return amt >= num;
		}
	}
}

//第一个是条件 第二个是注册资金u_zczj, u_zczj1
function zczjFlag(u_zczj, u_zczj1, index) {
	console.log(u_zczj, "u_zczj");
	console.log(u_zczj1, "u_zczj1");
	console.log(index, "index");

	const match = u_zczj
		?.replace(/＞/g, ">")
		.replace(/＜/g, "<")
		.replace(/≥/g, ">=")
		.replace(/≤/g, "<=")
		.match(/(<=|>=|<|>)(\d+)/);
	if (match) {
		const [_, symbol, number] = match;
		const num = parseFloat(number);
		const amt = getWan(u_zczj1);
		console.log(amt, "zczjFlag", num, "zczjFlag");
		// 符号匹配逻辑
		switch (symbol) {
			case "<":
				return amt < num;
			case ">":
				return amt > num;
			case "<=":
				return amt <= num;
			case ">=":
				return amt >= num;
		}
	}
}

//第一个是条件 第二个是成立时间u_zcsj, u_zcsj1
function zcsjFlag(inputDateStr, years, index) {
	// 将输入日期字符串转换为 Date 对象
	//封装年限判断函数
	// 将输入日期字符串转换为 Date 对象
	const inputDate = new Date(inputDateStr);

	// 获取当前日期
	const currentDate = new Date();

	// 计算指定年限之前的日期
	const pastDate = new Date();
	pastDate.setFullYear(currentDate.getFullYear() - years);
	if (!inputDateStr) {
		$NG.alert("成立时间不能为空");
		return false;
	}
	if (inputDate <= pastDate) {
		// 比较日期
		console.log(
			`第${index + 1}行,输入的日期距离今天已经过去了${years}年或更久`
		);
		return true;
	} else {
		$NG.alert(`第${index + 1}行,成立日期日期距离今天不足${years}年`);
		console.log(`输入的日期距离今天不足${years}年`);
		return false;
	}
}

//第一个是条件 第二个是分包额值u_db_amt1, u_fb_amt
function FbeFlag(u_db_amt1, u_fb_amt) {
	//分包额判断是否有满足的条件
	const match = u_db_amt1
		?.replace(/＞/g, ">")
		.replace(/＜/g, "<")
		.replace(/≥/g, ">=")
		.replace(/≤/g, "<=")
		.match(/(<=|>=|<|>)(\d+)/);

	if (match) {
		const [_, symbol, number] = match;
		const num = parseFloat(number);
		console.log(u_fb_amt, "u_fb_amt");

		const amt = getWan(u_fb_amt);
		console.log(amt, "amt", num, "num");
		// 符号匹配逻辑
		switch (symbol) {
			case "<":
				return amt < num;
			case ">":
				return amt > num;
			case "<=":
				return amt <= num;
			case ">=":
				return amt >= num;
		}
	}
	return false;
}

//把个位数人民币 转换成以万为单位向下取整
function getWan(num) {
	//如果不是数字返回0
	if (isNaN(Number(num))) {
		return 0;
	}
	return Math.floor(Number(num) / 10000);
}

//针对分包商认定 服务于工程 校验方案说明步骤

// 1.获取服务于工程表格信息 tab2Rows
// 2.获取服务于工程校验规则 JYGZ
// 3.根据注册资金和
